package com.yhq.basic.design.memento;

/**
 * @author hqyin
 * @date 2023/2/2 9:49 上午
 */
public class MementoTest {
    public static void main(String[] args) {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("state 1");
        originator.setState("state 2");
        Memento memento = originator.saveStateToMemento();
        careTaker.addMemento(memento);
        originator.setState("state 3");
        Memento memento3 = originator.saveStateToMemento();
        careTaker.addMemento(memento3);
        originator.setState("state 4");

        System.out.println("current state:" + originator.getState());
        originator.restoreState(careTaker.getLastMemento());
        System.out.println("恢复上一个状态,state:" + originator.getState());
        originator.restoreState(careTaker.getLastMemento());
        System.out.println("恢复上一个状态,state:" + originator.getState());


    }
}
